package com.wn.pettyloan.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wn.pettyloan.dto.PayDto;
import com.wn.pettyloan.dto.RepayAddDto;
import com.wn.pettyloan.dto.RepayDto;
import com.wn.pettyloan.entity.Repay;
import com.wn.pettyloan.entity.RepayRecord;
import com.wn.pettyloan.service.RepayRecordService;
import com.wn.pettyloan.service.RepayService;
import com.wn.pettyloan.util.Result;
import com.wn.pettyloan.util.utilentity.RepayPlan;
import com.wn.pettyloan.vo.RepayVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

/**
 * @program: pettyloan
 * @ClassName RepayController
 * @author: 汪江
 * @create: 2022-12-06 15:52
 **/
@RestController
@RequestMapping("repay")
public class RepayController {
    @Resource
    private RepayService repayService;
    @Resource
    private RepayRecordService repayRecordService;

    @PostMapping("query")
    public Result selAllRepay(@RequestBody RepayDto repayDto) {
        /** @Author 汪江
         * @Description selAllRepay
         * 查所有的还款信息，合同编号，用户，产品名，本金，利率，已还本金，已还总额
         * 返回该用户名下的合同，贷款本金，已还本金
         * 分页查询的返回数据的数量
         * @Date 15:30 2022/12/6
         * @Param []
         * @return com.wn.pettyloan.util.Result
         **/
        PageHelper.startPage(repayDto.getCurrentPage(), repayDto.getPageSize(), true);
        List<RepayVo> repayVos = repayService.selAllRepay(repayDto);
        PageInfo<RepayVo> pageInfo = new PageInfo<RepayVo>(repayVos);
        RepayVo repayVo = repayService.selTopInfo(repayDto);
        System.out.println(repayDto.toString());
        if (repayVos != null) {
            if (repayVo != null) {
                return Result.ok().data("repayList", repayVos).data("topInfo", repayVo).data("total", pageInfo.getTotal());
            } else {
                return Result.error();
            }
        } else {
            return Result.error();
        }
    }

//    @GetMapping("")
//    public Result addRepay(Integer contractId){
//        boolean b = repayService.addRepay(contractId);
//        if(b){
//            return Result.ok();
//        }else {
//            return Result.error();
//        }
//    }


}
